<?php
$cache_time=1;
require_once('./include/cache_start.php');
    require_once("./include/db_info.inc.php");
	require_once("./include/setlang.php");
	$view_title= "LOGIN";

	if (isset($_SESSION[$OJ_NAME.'_'.'user_id'])){
	echo "<a href=logout.php>Please logout First!</a>";
	exit(1);
}

function send_post($url, $post_data) {

	$postdata = http_build_query($post_data);
	$options = array(
		'http' => array(
			'method' => 'POST',
			'header' => 'Content-type:application/x-www-form-urlencoded',
			'content' => $postdata,
			'timeout' => 15 * 60 // 超时时间（单位:s）
		)
	);
	$context = stream_context_create($options);
	$result = file_get_contents($url, false, $context);

	return $result;
}

//使用方法
$post_data = array(
	'user_id' => 'admin',
	'password' => '123456'
);


/////////////////////////Template
/// OJ_LONG_LOGIN参数配置中是false
if($OJ_LONG_LOGIN==true&&isset($_COOKIE[$OJ_NAME."_user"])&&isset($_COOKIE[$OJ_NAME."_check"])){
	echo"<script>let xhr=new XMLHttpRequest();xhr.open('GET','login.php',true);xhr.send();setTimeout('history.go(-1)',500);</script>";
}
else if(isset($_POST[ 'user_id' ])){
	//发到自动登录的php
	$user_id = $_POST[ 'user_id' ];
	$password = $_POST[ 'password' ];
//	setcookie('$user_id_cookie',$user_id);
//	setcookie('$password_cookie',$password);

//	$re = send_post("template/".$OJ_TEMPLATE."/loginpage-test.php", $post_data);
	include("template/".$OJ_TEMPLATE."/loginpage-test.php");

}else{
	require("template/".$OJ_TEMPLATE."/loginpage.php");
}

/////////////////////////Common foot
if(file_exists('./include/cache_end.php'))
	require_once('./include/cache_end.php');
?>
